package com.pureut.storage.controller;


import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.storage.dto.*;
import com.pureut.storage.service.WmsStockInfoService;
import com.pureut.storage.vo.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.pureut.system.api.vo.QualityFreezeVo;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.List;

/**
 * @author: CM
 * @date: 2023/1/9  15:00
 */
@RestController
@RequestMapping("/wmsStock")
public class WmsStockInfoController extends BaseController {

    @Resource
    private WmsStockInfoService wmsStockInfoService;

    /**
     * 根据物料编码和批次号获取仓库信息
     */
    @GetMapping("/getMessage")
    public AjaxResult getStockInfo(WmsStockInfoVo wmsStockInfoVo) throws ParseException {
        return AjaxResult.success(wmsStockInfoService.getStockInfo(wmsStockInfoVo));
    }

    /**
     * 根据物料号码修改单据状态
     */
    @PostMapping("/updateStatus")
    public AjaxResult updateStatus(@RequestBody WmsStockInfoVo wmsStockInfoVo) {
        return toAjax(wmsStockInfoService.updateStatus(wmsStockInfoVo));
    }

    /**
     * 根据母卷号码查询库存信息
     */
    @GetMapping("/selectMasterVolumeList/{masterVolumeNumber}")
    public AjaxResult selectMasterVolumeList(@PathVariable("masterVolumeNumber") String masterVolumeNumber) {
        return AjaxResult.success(wmsStockInfoService.selectMasterVolumeList(masterVolumeNumber));
    }

    /**
     * 修改库存卷长
     */
    @Log(title = "修改库存卷长", businessType = BusinessType.UPDATE)
    @PutMapping("/updateStockInfoById")
    public AjaxResult updateStockInfoById(@RequestBody WmsStockInfoVo wmsStockInfoVo) {
        return toAjax(wmsStockInfoService.updateStockInfoById(wmsStockInfoVo));
    }

    /**
     * 删除库存
     */
    @Log(title = "删除库存", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{truncationMasterVolumeNumber}")
    public AjaxResult remove(@PathVariable("truncationMasterVolumeNumber") String truncationMasterVolumeNumber) {
        return toAjax(wmsStockInfoService.deleteStockInfoById(truncationMasterVolumeNumber));
    }

    /**
     * 查询仓库信息（品质检验冻结查询）
     */
    @PostMapping("/getFreezeStockList")
    public AjaxResult getFreezeStockList(@RequestBody QualityFreezeVo qualityFreezeVo) {
        return AjaxResult.success(wmsStockInfoService.getFreezeStockList(qualityFreezeVo));
    }

    /**
     * 仓库状态批量修改
     */
    @PostMapping("/getUpdate")
    public AjaxResult getUpdate(@RequestBody WarehouseStatusUpdateVo warehouseStatusUpdateVo) {
        return toAjax(wmsStockInfoService.getUpdate(warehouseStatusUpdateVo));
    }

    /**
     * 库存汇总
     */
    @GetMapping("/sumStock")
    public TableDataInfo sumStock(CheckStockVo checkStockVo) {
        startPage();
        //查询其他出库列表
        List<WmsStockInfoSumDto> list = wmsStockInfoService.sumStock(checkStockVo);
        return getDataTable(list);
    }

    /**
     * 库存明细列表
     */
    @GetMapping("/list")
    public TableDataInfo getList(CheckStockVo checkStockVo) {
        startPage();
        //查询其他出库列表
        List<WmsStockInfoDto> list = wmsStockInfoService.getList(checkStockVo);
        return getDataTable(list);
    }

    /**
     * 库存盘点中物料
     */
    @GetMapping("/allotList")
    public TableDataInfo getAllotList(CheckStockVo checkStockVo) {
        startPage();
        //查询其他出库列表
        List<WmsStockInfoDto> list = wmsStockInfoService.getAllotList(checkStockVo);
        return getDataTable(list);
    }

    /**
     * 库存新增
     */
    @PostMapping("/add")
    public AjaxResult addWmsStock(@Validated @RequestBody WmsStockInfoVo wmsStockInfoVo) {
        return toAjax(wmsStockInfoService.add(wmsStockInfoVo));
    }

    /**
     * 修改库存状态更新为“在库”
     */
    @PostMapping("/updateStockStatus")
    public AjaxResult updateStatus(@RequestBody UpdateStatusVo updateStatusVo) {
        return toAjax(wmsStockInfoService.updateStockStatus(updateStatusVo));
    }

    /**
     * 物料号码获取仓库数据
     */
    @GetMapping("/getDataByCategoryAndCode")
    public AjaxResult getDataByCategoryAndCode(String materialNumber) {
        return AjaxResult.success(wmsStockInfoService.getDataByCategoryAndCode(materialNumber));
    }

    /**
     * 修正母卷条码
     */
    @Log(title = "修正母卷条码", businessType = BusinessType.UPDATE)
    @PutMapping("/updateSpunlace")
    public AjaxResult updateSpunlace(@RequestBody WmsStockInfoVo wmsStockInfoVo) {
        return toAjax(wmsStockInfoService.updateSpunlace(wmsStockInfoVo));
    }

    /**
     * 制令单号查找关联的物料号码，状态为返工
     */
    @GetMapping("/getStockInfoMo")
    public AjaxResult getStockInfoMo(MoStockInfoVo moStockInfoVo) {
        return AjaxResult.success(wmsStockInfoService.getStockInfoMo(moStockInfoVo));
    }

    /**
     * 采购入库单号查找关联的物料号码，状态为批退
     */
    @GetMapping("/getPurchase")
    public AjaxResult getPurchase(PurchaseStockVo purchaseStockVo) {
        return AjaxResult.success(wmsStockInfoService.getPurchase(purchaseStockVo));
    }

    /**
     * 根据物料编码获取该物料在仓库中的净重之和(feign调用)
     */
    @GetMapping("/getSum")
    public String getSum(String materialCode) {
        return wmsStockInfoService.getSum(materialCode);
    }

    /**
     * 根据物料编码获取库存重量（feign调用 委外入库页面使用）
     */
    @GetMapping("/getStockWeight")
    public double getStockWeight(String materialCode) {
        return wmsStockInfoService.getStockWeight(materialCode);
    }

    /**
     * 根据物料号码修改库存状态为冻结
     */
    @GetMapping("/updateStatusThaw")
    public void updateStatusThaw(String materialNumber) {
        wmsStockInfoService.updateStatusThaw(materialNumber);
    }

    /**
     * 查询基础信息（feign调用 物料追溯页面使用）
     *
     * @param wsiCategory, wsiMaterialNumber
     * @return
     */
    @GetMapping("/getRetrospectManageList")
    public AjaxResult getRetrospectManageList(Long wsiCategory, String wsiMaterialNumber) {
        return AjaxResult.success(wmsStockInfoService.getRetrospectManageList(wsiCategory, wsiMaterialNumber));
    }

    /**
     * 物料履历（feign调用 物料追溯页面使用）
     *
     * @param wsiCategory, wsiMaterialNumber
     * @return
     */
    @GetMapping("/MaterialResumeList")
    public AjaxResult MaterialResumeList(Long wsiCategory, String wsiMaterialNumber) {
        return AjaxResult.success(wmsStockInfoService.MaterialResumeList(wsiCategory, wsiMaterialNumber));
    }

    /**
     * 查询同批次物料 （feign调用 物料追溯页面使用）
     */
    @GetMapping("/getRetrospectMaterialList")
    public AjaxResult getRetrospectMaterialList(String wsiMaterialNumber) {
        return AjaxResult.success(wmsStockInfoService.getRetrospectMaterialList(wsiMaterialNumber));
    }

    /**
     * 查询同批次物料 （feign调用 产品追溯页面使用）
     */
    @GetMapping("/getRetrospectProductList")
    public AjaxResult getRetrospectProductList(String codingType,String wsiMaterialNumber) {
        return AjaxResult.success(wmsStockInfoService.getRetrospectProductList(codingType,wsiMaterialNumber));
    }

    /**
     * 查询基础信息（feign调用 产品追溯页面使用）
     *
     * @param codingType, wsiMaterialNumber
     * @return
     */
    @GetMapping("/getProductTraceabilityList")
    public AjaxResult getProductTraceabilityList(String codingType, String wsiMaterialNumber) {
        return AjaxResult.success(wmsStockInfoService.getProductTraceabilityList(codingType, wsiMaterialNumber));
    }

    /**
     * 产品履历（feign调用 产品追溯页面使用）
     *
     * @param codingType, wsiMaterialNumber
     * @return
     */
    @GetMapping("/getProductPersonalDetails")
    public AjaxResult getProductPersonalDetails(String codingType, String wsiMaterialNumber) {
        return AjaxResult.success(wmsStockInfoService.getProductPersonalDetails(codingType, wsiMaterialNumber));
    }

    /**
     * 库存汇总
     */
    @GetMapping("/getInventorySummaryList")
    public TableDataInfo getInventorySummaryList(WmsStockInfoVo wmsStockInfoVo) {
        //查询其他出库列表
        List<InventorySummaryDto> inventorySummaryList = wmsStockInfoService.getInventorySummaryList(wmsStockInfoVo);
        return getDataTable(inventorySummaryList);
    }

    /**
     * 原料明细
     */
    @GetMapping("/getInventoryMaterialDetailed")
    public TableDataInfo getInventoryMaterialDetailed(WmsStockInfoVo wmsStockInfoVo) {
        //查询原料明细列表
        List<DetailsMaterialsDto> inventoryMaterialDetailed = wmsStockInfoService.getInventoryMaterialDetailed(wmsStockInfoVo);
        return getDataTable(inventoryMaterialDetailed);
    }

    /**
     * 辅料明细
     */
    @GetMapping("/getInventoryAccessoriesDetailed")
    public TableDataInfo getInventoryAccessoriesDetailed(WmsStockInfoVo wmsStockInfoVo) {
        //查询辅料明细列表
        List<DetailsMaterialsDto> inventoryAccessoriesDetailed = wmsStockInfoService.getInventoryAccessoriesDetailed(wmsStockInfoVo);
        return getDataTable(inventoryAccessoriesDetailed);
    }

    /**
     * 成品明细
     */
    @GetMapping("/getInventoryFinishProductDetailed")
    public TableDataInfo getInventoryFinishProductDetailed(WmsStockInfoVo wmsStockInfoVo) {
        //查询成品明细列表
        List<DetailsMaterialsDto> inventoryFinishProductDetailed = wmsStockInfoService.getInventoryFinishProductDetailed(wmsStockInfoVo);
        return getDataTable(inventoryFinishProductDetailed);
    }

    /**
     * 半成品明细
     */
    @GetMapping("/getInventoryMaterialHalfDetailed")
    public TableDataInfo getInventoryMaterialHalfDetailed(WmsStockInfoVo wmsStockInfoVo) {
        //查询半成品明细列表
        List<DetailsMaterialsDto> inventoryMaterialHalfDetailed = wmsStockInfoService.getInventoryMaterialHalfDetailed(wmsStockInfoVo);
        return getDataTable(inventoryMaterialHalfDetailed);
    }

    /**
     * 废料明细
     */
    @GetMapping("/getInventoryWasteDetailed")
    public TableDataInfo getInventoryWasteDetailed(WmsStockInfoVo wmsStockInfoVo) {
        //查询废料明细列表
        List<DetailsMaterialsDto> inventoryWasteDetailed = wmsStockInfoService.getInventoryWasteDetailed(wmsStockInfoVo);
        return getDataTable(inventoryWasteDetailed);
    }


    /**
     * 委外发货物料汇总
     */
    @GetMapping("/outsourceSum")
    public TableDataInfo outsourceSum(OutsourceSumVo outsourceSumVo) {
        startPage();
        //查询其他出库列表
        List<OutsourceSumDto> list = wmsStockInfoService.outsourceSum(outsourceSumVo);
        return getDataTable(list);
    }

    /**
     * 根据母卷号码删除仓库数据（fegin调用）
     */
    @GetMapping("/deleteByMasterVolumeNum")
    public void deleteByMasterVolumeNum(String masterVolumeNum) {
        wmsStockInfoService.deleteByMasterVolumeNum(masterVolumeNum);
    }

    /**
     * 根据母卷号码查询母卷
     */
    @GetMapping("/selectProductStockInfoById")
    public AjaxResult selectProductStockInfoById(String wsiMaterialNumber) {
        return AjaxResult.success(wmsStockInfoService.selectProductStockInfoById(wsiMaterialNumber));
    }

    /**
     * 品质处理修改对应物料等级
     */
    @PostMapping("/updateMaterialGrade")
    public AjaxResult updateMaterialGrade(@RequestBody UpdateGradeVo updateGradeVo) {
        return toAjax(wmsStockInfoService.updateMaterialGrade(updateGradeVo));
    }

    /**
     * 消息提醒-最小安全库存
     */
    @GetMapping("/maxStock")
    public void maxStock() throws Exception {
        wmsStockInfoService.maxStock();
    }

    /**
     * 消息提醒-保质期
     */
    @GetMapping("/expirationDate")
    public void expirationDate() throws Exception {
        wmsStockInfoService.expirationDate();
    }


    /**
     * 消息提醒-复检提醒
     */
    @GetMapping("/recheck")
    public void recheck() throws Exception {
        wmsStockInfoService.recheck();
    }


}
